package com.weimei.conversionTreasure.http;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;


import com.gtdev5.geetolsdk.mylibrary.beans.LoginInfoBean;
import com.weimei.conversionTreasure.http.entity.BalanceDetailBean;
import com.weimei.conversionTreasure.http.entity.BaseResult;
import com.weimei.conversionTreasure.http.entity.BillBean;
import com.weimei.conversionTreasure.http.entity.ComputerBean;
import com.weimei.conversionTreasure.http.entity.CustomListBean;
import com.weimei.conversionTreasure.http.entity.DealerDetailBean;
import com.weimei.conversionTreasure.http.entity.FaJiaoDetailBean;
import com.weimei.conversionTreasure.http.entity.FaJiaoListBean;
import com.weimei.conversionTreasure.http.entity.FormulaBean;
import com.weimei.conversionTreasure.http.entity.FormulaDetailBean;
import com.weimei.conversionTreasure.http.entity.FormulaListBean;
import com.weimei.conversionTreasure.http.entity.KgjsBean;
import com.weimei.conversionTreasure.http.entity.MonthBean;
import com.weimei.conversionTreasure.http.entity.MonthDetailBean;
import com.weimei.conversionTreasure.http.entity.PaoLiangDetailBean;
import com.weimei.conversionTreasure.http.entity.PaoLiangListBean;
import com.weimei.conversionTreasure.http.entity.SaveListBean;
import com.weimei.conversionTreasure.http.entity.SelKhBean;
import com.weimei.conversionTreasure.http.entity.SheRuBean;
import com.weimei.conversionTreasure.http.entity.UserBean;
import com.weimei.conversionTreasure.http.entity.YMonthDetailBean;
import com.weimei.conversionTreasure.http.entity.YearBean;

import java.util.Map;

import io.reactivex.Observable;
import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.utils.SPUtils;

/**
 * MVVM的Model层，统一模块的数据仓库，包含网络数据和本地数据（一个应用可以有多个Repositor）
 * Created by goldze on 2019/3/26.
 */
public class Repository extends BaseModel implements HttpDataSource, LocalDataSource {
    private volatile static Repository INSTANCE = null;
    private final HttpDataSource mHttpDataSource;

    private final LocalDataSource mLocalDataSource;

    private Repository(@NonNull HttpDataSource httpDataSource,
                       @NonNull LocalDataSource localDataSource) {
        this.mHttpDataSource = httpDataSource;
        this.mLocalDataSource = localDataSource;
    }

    public static Repository getInstance(HttpDataSource httpDataSource,
                                         LocalDataSource localDataSource) {
        if (INSTANCE == null) {
            synchronized (Repository.class) {
                if (INSTANCE == null) {
                    INSTANCE = new Repository(httpDataSource, localDataSource);
                }
            }
        }
        return INSTANCE;
    }

    @VisibleForTesting
    public static void destroyInstance() {
        INSTANCE = null;
    }

    @Override
    public void setLogin(LoginInfoBean loginInfoBean) {
        mLocalDataSource.setLogin(loginInfoBean);
    }

    @Override
    public LoginInfoBean getLoginInfo() {
        return mLocalDataSource.getLoginInfo();
    }

    @Override
    public boolean isLogin() {
        SPUtils.getInstance().put("login",mLocalDataSource.isLogin());
        return mLocalDataSource.isLogin();
    }

    @Override
    public void saveUserName(String userName) {
        mLocalDataSource.saveUserName(userName);
    }

    @Override
    public void savePassword(String password) {
        mLocalDataSource.savePassword(password);
    }

    @Override
    public String getUserName() {
        return mLocalDataSource.getUserName();
    }

    @Override
    public String getPassword() {
        return mLocalDataSource.getPassword();
    }


    @Override
    public Observable<BaseResult> userLogin(Map<String, String> map) {
        return mHttpDataSource.userLogin(map);
    }

    @Override
    public Observable<UserBean> getUser(Map<String, String> map) {
        return mHttpDataSource.getUser(map);
    }

    @Override
    public Observable<BaseResult> feedBack(Map<String, String> map) {
        return mHttpDataSource.feedBack(map);
    }

    @Override
    public Observable<BaseResult> logOff(Map<String, String> map) {
        return mHttpDataSource.logOff(map);
    }

    @Override
    public Observable<BaseResult> editUser(Map<String, String> map) {
        return mHttpDataSource.editUser(map);
    }

    @Override
    public Observable<BaseResult> addFerment(Map<String, String> map) {
        return mHttpDataSource.addFerment(map);
    }

    @Override
    public Observable<FaJiaoDetailBean> fermentDetails(Map<String, String> map) {
        return mHttpDataSource.fermentDetails(map);
    }

    @Override
    public Observable<FaJiaoListBean> fermentList(Map<String, String> map) {
        return mHttpDataSource.fermentList(map);
    }

    @Override
    public Observable<BaseResult> addSoakgrain(Map<String, String> map) {
        return mHttpDataSource.addSoakgrain(map);
    }

    @Override
    public Observable<PaoLiangListBean> soakgrainList(Map<String, String> map) {
        return mHttpDataSource.soakgrainList(map);
    }

    @Override
    public Observable<PaoLiangDetailBean> soakgrainInfo(Map<String, String> map) {
        return mHttpDataSource.soakgrainInfo(map);
    }

    @Override
    public Observable<BaseResult> delete_soakgrain(Map<String, String> map) {
        return mHttpDataSource.delete_soakgrain(map);
    }

    @Override
    public Observable<BaseResult> delete_ferment(Map<String, String> map) {
        return mHttpDataSource.delete_ferment(map);
    }

    @Override
    public Observable<BaseResult> adddealer(Map<String, String> map) {
        return mHttpDataSource.adddealer(map);
    }

    @Override
    public Observable<BaseResult> addcustom(Map<String, String> map) {
        return mHttpDataSource.addcustom(map);
    }

    @Override
    public Observable<CustomListBean> customlist(Map<String, String> map) {
        return mHttpDataSource.customlist(map);
    }

    @Override
    public Observable<CustomListBean> dealerlist(Map<String, String> map) {
        return mHttpDataSource.dealerlist(map);
    }

    @Override
    public Observable<BaseResult> delete_custom(Map<String, String> map) {
        return mHttpDataSource.delete_custom(map);
    }

    @Override
    public Observable<DealerDetailBean> dealer_details(Map<String, String> map) {
        return mHttpDataSource.dealer_details(map);
    }

    @Override
    public Observable<BaseResult> delete_balance(Map<String, String> map) {
        return mHttpDataSource.delete_balance(map);
    }

    @Override
    public Observable<BaseResult> add_balance(Map<String, String> map) {
        return mHttpDataSource.add_balance(map);
    }

    @Override
    public Observable<BaseResult> edit_balance(Map<String, String> map) {
        return mHttpDataSource.edit_balance(map);
    }

    @Override
    public Observable<BaseResult> seach_transaction(Map<String, String> map) {
        return mHttpDataSource.seach_transaction(map);
    }

    @Override
    public Observable<BaseResult> add_transaction(Map<String, String> map) {
        return mHttpDataSource.add_transaction(map);
    }

    @Override
    public Observable<BaseResult> delete_transaction(Map<String, String> map) {
        return mHttpDataSource.delete_transaction(map);
    }

    @Override
    public Observable<SelKhBean> custom_sort(Map<String, String> map) {
        return mHttpDataSource.custom_sort(map);
    }

    @Override
    public Observable<SelKhBean> custom_dealer(Map<String, String> map) {
        return mHttpDataSource.custom_dealer(map);
    }

    @Override
    public Observable<BaseResult> addbudget(Map<String, String> map) {
        return mHttpDataSource.addbudget(map);
    }

    @Override
    public Observable<BaseResult> addstorage(Map<String, String> map) {
        return mHttpDataSource.addstorage(map);
    }

    @Override
    public Observable<SaveListBean> storagelist(Map<String, String> map) {
        return mHttpDataSource.storagelist(map);
    }

    @Override
    public Observable<BaseResult> storageinfo(Map<String, String> map) {
        return mHttpDataSource.storageinfo(map);
    }

    @Override
    public Observable<BaseResult> addblanking(Map<String, String> map) {
        return mHttpDataSource.addblanking(map);
    }

    @Override
    public Observable<SaveListBean> blankinglist(Map<String, String> map) {
        return mHttpDataSource.blankinglist(map);
    }

    @Override
    public Observable<BaseResult> blankinginfo(Map<String, String> map) {
        return mHttpDataSource.blankinginfo(map);
    }

    @Override
    public Observable<BaseResult> deletestorage(Map<String, String> map) {
        return mHttpDataSource.deletestorage(map);
    }

    @Override
    public Observable<BillBean> mybill(Map<String, String> map) {
        return mHttpDataSource.mybill(map);
    }

    @Override
    public Observable<YMonthDetailBean> month_chart(Map<String, String> map) {
        return mHttpDataSource.month_chart(map);
    }

    @Override
    public Observable<YearBean> year_chart(Map<String, String> map) {
        return mHttpDataSource.year_chart(map);
    }

    @Override
    public Observable<MonthDetailBean> month_details(Map<String, String> map) {
        return mHttpDataSource.month_details(map);
    }

    @Override
    public Observable<MonthBean> monthly_stat(Map<String, String> map) {
        return mHttpDataSource.monthly_stat(map);
    }

    @Override
    public Observable<BaseResult> editbudget(Map<String, String> map) {
        return mHttpDataSource.editbudget(map);
    }

    @Override
    public Observable<BalanceDetailBean> balance_details(Map<String, String> map) {
        return mHttpDataSource.balance_details(map);
    }

    @Override
    public Observable<ComputerBean> proofspirit(Map<String, String> map) {
        return mHttpDataSource.proofspirit(map);
    }

    @Override
    public Observable<ComputerBean> computedensity(Map<String, String> map) {
        return mHttpDataSource.computedensity(map);
    }

    @Override
    public Observable<ComputerBean> getwine(Map<String, String> map) {
        return mHttpDataSource.getwine(map);
    }

    @Override
    public Observable<KgjsBean> blending_weight(Map<String, String> map) {
        return mHttpDataSource.blending_weight(map);
    }

    @Override
    public Observable<ComputerBean> getvolume(Map<String, String> map) {
        return mHttpDataSource.getvolume(map);
    }

    @Override
    public Observable<ComputerBean> computeweight(Map<String, String> map) {
        return mHttpDataSource.computeweight(map);
    }

    @Override
    public Observable<SheRuBean> water_addition(Map<String, String> map) {
        return mHttpDataSource.water_addition(map);
    }

    @Override
    public Observable<SheRuBean> target_alcohol(Map<String, String> map) {
        return mHttpDataSource.target_alcohol(map);
    }


    @Override
    public Observable<SheRuBean> costing(Map<String, String> map) {
        return mHttpDataSource.costing(map);
    }

    @Override
    public Observable<SheRuBean> intake_calculation(Map<String, String> map) {
        return mHttpDataSource.intake_calculation(map);
    }

    @Override
    public Observable<SheRuBean> degrees(Map<String, String> map) {
        return mHttpDataSource.degrees(map);
    }

    @Override
    public Observable<SheRuBean> elevations(Map<String, String> map) {
        return mHttpDataSource.elevations(map);
    }

    @Override
    public Observable<BaseResult> addformula(Map<String, String> map) {
        return mHttpDataSource.addformula(map);
    }

    @Override
    public Observable<FormulaListBean> formulalist(Map<String, String> map) {
        return mHttpDataSource.formulalist(map);
    }

    @Override
    public Observable<FormulaDetailBean> formuladetails(Map<String, String> map) {
        return mHttpDataSource.formuladetails(map);
    }

    @Override
    public Observable<FormulaBean> recent_formula(Map<String, String> map) {
        return mHttpDataSource.recent_formula(map);
    }

    @Override
    public Observable<BaseResult> delete_formula(Map<String, String> map) {
        return mHttpDataSource.delete_formula(map);
    }

    @Override
    public Observable<KgjsBean> blending_volume(Map<String, String> map) {
        return mHttpDataSource.blending_volume(map);
    }
}
